package pers.liu.yibandemo.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import pers.liu.yibandemo.entity.SchoolDepartment;
import pers.liu.yibandemo.mapper.SchoolDepartmentMapper;

import java.util.List;

@Service
public class SchoolDepartmentService extends ServiceImpl<SchoolDepartmentMapper, SchoolDepartment> {

    @Autowired
    private SchoolDepartmentMapper schoolDepartmentMapper;

    // 添加学校部门联系信息
    public void addDepartment(SchoolDepartment department) {
        schoolDepartmentMapper.insert(department);
    }

    // 分页查询学校部门联系信息
    public IPage<SchoolDepartment> getDepartmentsByPage(int pageNum, int pageSize) {
        Page<SchoolDepartment> page = new Page<>(pageNum, pageSize);
        IPage<SchoolDepartment> result = schoolDepartmentMapper.selectPage(page, null);
        return result;
    }

    // 根据部门ID查询部门信息
    public SchoolDepartment getDepartmentById(Long departmentId) {
        return schoolDepartmentMapper.selectById(departmentId);
    }

    // 查询所有学校部门联系信息
    public List<SchoolDepartment> getAllDepartments() {

        return schoolDepartmentMapper.selectList(null);
    }

    // 更新学校部门联系信息
    public void updateDepartment(SchoolDepartment department) {

        schoolDepartmentMapper.updateById(department);
    }

    // 删除学校部门联系信息
    public void deleteDepartment(Long departmentId) {

        schoolDepartmentMapper.deleteById(departmentId);
    }
}
